#include <algorithm>
#include <cstdio>
const int N = 100010, mod = 99999997;
struct Node {
	int id, val;
	bool operator<(const Node rph) const { return val < rph.val; }
} a[N], b[N];
int n;
int ranka[N], rankb[N], t[N], tmp[N];
inline int lowbit(int x) { return x & (-x); }
inline void add(int index) {
	while (index <= n) {
		++t[index];
		index += lowbit(index);
	}
}
inline int query(int index) {
	int res = 0;
	while (index >= 1) {
		res += t[index];
		index -= lowbit(index);
	}
	return res;
}
int main() {
#ifndef ONLINE_JUDGE
#ifdef LOCAL
	freopen("testdata.in", "r", stdin);
	freopen("testdata.out", "w", stdout);
#endif
#ifndef LOCAL
	freopen(".in", "r", stdin);
	freopen(".out", "w", stdout);
#endif
#endif

	scanf("%d", &n);
	for (register int i = 1; i <= n; ++i) {
		scanf("%d", &a[i].val);
		a[i].id = i;
	}
	std::sort(a + 1, a + n + 1);
	for (register int i = 1; i <= n; ++i) {
		scanf("%d", &b[i].val);
		b[i].id = i;
	}
	std::sort(b + 1, b + n + 1);
	for (int i = 1; i <= n; ++i) { tmp[a[i].id] = b[i].id; }
	int ans = 0;
	for (register int i = n; i; --i) {
		ans += query(tmp[i] - 1);
		if (ans >= mod) ans -= mod;
		add(tmp[i]);
	}
	printf("%d", (ans % mod + mod) % mod);
	return 0;
}